/* 
 * Copyright 2013 Sébastien Mouquet.
 * 
 * This file is part of ECovoiturage.
 * 
 * ECovoiturage is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * ECovoiturage is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Foobar. If not, see http://www.gnu.org/licenses/.
 */
package com.smouquet.ecovoiturage.core.domain;

import java.io.Serializable;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

/**
 * 
 * @author sebastien.mouquet
 */
@Entity
@Table(name="trajet_utilisateur")
public class TrajetUtilisateur implements Serializable 
{
    @EmbeddedId
    @AttributeOverrides
    ({
        @AttributeOverride(name="fkTrajet", column=@Column(name="fk_trajet", nullable=false)),
        @AttributeOverride(name="fkUtilisateur", column=@Column(name="fk_utilisateur", nullable=false))
    })
    private TrajetUnitisateurId id;
    
    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name = "fk_trajet", nullable=false, insertable=false, updatable=false)
    private Trajet trajet;
    
    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name = "fk_utilisateur", nullable=false, insertable=false, updatable=false)
    private Utilisateur utilisateur;
    
    @Column(name="nb_places", nullable=false)
    private Integer nbPlaces;
    
    
    public TrajetUtilisateur() {}


    public TrajetUnitisateurId getId() {
        return id;
    }

    public void setId(TrajetUnitisateurId id) {
        this.id = id;
    }
    
    public Trajet getTrajet() {
        return trajet;
    }
    
    public void setTrajet(Trajet trajet) {
        this.trajet = trajet;
    }
    
    public Utilisateur getUtilisateur() {
        return utilisateur;
    }
    
    public void setUtilisateur(Utilisateur utilisateur) {
        this.utilisateur = utilisateur;
    }
    
    public Integer getNbPlaces() {
        return nbPlaces;
    }

    public void setNbPlaces(Integer nbPlaces) {
        this.nbPlaces = nbPlaces;
    }
    

    @Override
    public boolean equals(Object obj)
    {
        if(this == obj) {
            return true;
        }
        if(obj == null || !(obj instanceof TrajetUtilisateur)) {
            return false;
        }
        TrajetUtilisateur that = (TrajetUtilisateur) obj;
        if(id != null ? !id.equals(that.getId()) : that.getId() != null) {
            return false;
        }
        return true;
    }
 
    @Override
    public int hashCode()
    {
        return (id != null ? id.hashCode() : 0);
    }
}
